import { createSlice, PayloadAction } from "@reduxjs/toolkit";

export type UserInfoStateType = {
  userId: number | undefined;
  userName: string | undefined;
  nickName: string | undefined;
  isAdmin: boolean;
};

const INIT_STATE: UserInfoStateType = {
  userId: undefined,
  userName: undefined,
  nickName: undefined,
  isAdmin: false,
};

const userInfoSlice = createSlice({
  name: "userInfo",
  initialState: INIT_STATE,
  reducers: {
    loginReducer: (
      state: UserInfoStateType,
      action: PayloadAction<UserInfoStateType>
    ) => action.payload,

    logoutReducer: () => INIT_STATE,
  },
});

export const { loginReducer, logoutReducer } = userInfoSlice.actions;

export default userInfoSlice.reducer;
